
//나이 데이터 수집용.
var ages = { a0: 0, a10: 0, a20: 0, a30: 0, a40: 0, a50: 0, a60: 0, a70: 0 };
var areas;

function init() {
	
	var json = JSON.parse( $("#json").html() );
	
	for ( var i = 0; i < json.loginList.length; i++ ) {
		//전체.
		if ( json.loginList[i].t_type == "all" ) {
			var temp1 = json.loginList[i].day.split(" ");
            var temp2 = temp1[0].split("-");
            var day = temp2[2];
            
            $("#yearAndMonth").html( "< " + temp2[0] + "년 " + temp2[1] + "월 >" );
            
            var tempJ = json.loginList[i];
            
            for ( var j = 1; j <= 24; j++ ) {
            	var count = $("#"+day).html();
            	var tempV = $(tempJ).attr("h"+j);
            	if ( tempV != "" && tempV != null ) {
            		if ( count == "" ) {
                        count = tempV;
                    } else {
                        count = parseInt( count ) + parseInt( tempV );
                    }
            	}
            	$("#"+day).html( count );
            }
        
		} else if ( json.loginList[i].t_type == "marry" ) {
			//결혼유무.
			if( json.loginList[i].t_value == "true" ) {
				var marry_true = $("#marry_true").html();
				var tempJ = json.loginList[i];
				for ( var j = 1; j <= 24; j++ ) {
					var tempV = $(tempJ).attr("h"+j);
					if ( tempV != "" && tempV != null ) {
						marry_true = parseInt( marry_true + tempV );
						$("#marry_true").html( marry_true );
					}
				}
			} else {
				var marry_false = $("#marry_false").html();
				var tempJ = json.loginList[i];
				for ( var j = 1; j <= 24; j++ ) {
					var tempV = $(tempJ).attr("h"+j);
					if ( tempV != "" && tempV != null ) {
						marry_false = parseInt( marry_false + tempV );
						$("#marry_false").html( marry_false );
					}
				}
			}
		} else if ( json.loginList[i].t_type == "age" ) {
			//나이대.
			var tempJ = json.loginList[i];
			for ( var j = 1; j <= 24; j++ ) {
				var tempV = $(ages).attr("a"+tempJ.t_value);
				tempV += parseInt( $(tempJ).attr("h"+j) );
				$(ages).attr("a"+tempJ.t_value, tempV);
			}
		} else if ( json.loginList[i].t_type == "area" ) {
			//지역별.
			var tempJ = json.loginList[i];
			
			
		} else {
			continue;
		}
	}
	//나이대 높은순 정렬.
	var ageArray = new Array(8);
	for ( var i = 0; i < ageArray.length; i++ ) {
		ageArray[i] = {
			"age": "a"+(i*10),
			"count": $(ages).attr("a"+(i*10))
		};
	}
	for ( var i = 0; i < ageArray.length - 1; i++ ) {
		for ( var j = i+1; j < ageArray.length; j++ ) {
			if ( ageArray[i].count < ageArray[j].count ) {
				var temp = ageArray[i];
				ageArray[i] = ageArray[j];
				ageArray[j] = temp;
			}
		}
	}
	for ( var i = 0; i < ageArray.length; i++ ) {
		$("#age"+(i+1)).html( ageArray[i].age.substring(1) + "대" );
		$("#ageCount"+(i+1)).html( ageArray[i].count );
	}
	
	//합계.
	for( var i = 1; i <= 31; i++ ) {
		var sum = $("#sum").html();
		if ( $("#"+i).html() != "" ) {
			sum += parseInt( $("#"+i).html() );
		}
		$("#sum").html( sum );
	}
}